<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<title>系部管理</title>
		<include file='Layout:ins_css' />
		<style type="text/css">
			#addBtn {
				float: right;
				margin: -7px -6px 9px;
			}
			
			.ibox-title {
				height: 46px;
			}
			
			.b-search {
				margin-left: 3px;
				float: right;
				padding: 5px 9px;
				background-color: #436EEE;
				border-color: #436EEE;
			}
			
			.price-div {
				/*float: left;*/
				margin: 12px 0px 6px 16px;
			}
			
			.price-div input {
				width: 8em;
				float: left;
				margin-right: 6px;
			}
			
			.price-div p {
				line-height: 25px;
				margin-right: 6px;
				float: left;
			}
			
			.price-div select {
				float: left;
				width: 60%;
				max-width: 16em;
				margin-right: 10px;
			}

			#langueType {
				height: 32px;
			}
			
			.select2-drop {
				z-index: 10050 !important;
			}
			
			.select2-search-choice-close {
				margin-top: 0 !important;
				right: 2px !important;
				min-height: 10px;
			}
			
			.select2-search-choice-close:before {
				color: black !important;
			}
			/*防止select2不会自动失去焦点*/
			
			.select2-container {
				z-index: 16000 !important;
			}
			
			.select2-drop-mask {
				z-index: 15990 !important;
			}
			
			.select2-drop-active {
				z-index: 15995 !important;
			}
			
			.staff {
				margin-top: 6px;
			}
			
			.nationality {
				margin-right: 15px;
			}
			div.dataTables_length label{
				width: 100%;
				float: left;
				text-align: left;
				font-weight: normal;
			}


			div.dataTables_filter label input{
				 width: 100%;
			 }

		</style>
	</head>

	<body>
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>系部管理</h5>
							<button class="btn btn-primary" id="addBtn">新增</button>
						</div>
						<div class="row s-row">
							<div class="col-sm-12">
								<div class="price-div">
									<form class="form-horizontal">
										<div class="form-group cyf-form-group">
											<div class="col-sm-4" style="margin-top: 10px; margin-bottom: 10px">
												<label style="float: left" class="col-sm-4 control-label cvbnm">学院: </label>
												<select class="form-control" id="college_id" name="college_id" style="min-height: 35px">
													<option value="0">全部</option>
													<volist name="college_info" id="college_info">
														<option value="{$college_info.sch_id}">{$college_info.sch_name}</option>
													</volist>
												</select>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
						<div class="ibox-content">
							<table class="table table-striped table-bordered table-hover dataTables-example" style="vertical-align: inherit;width: 100%">
								<thead>
									<tr>
										<th class="hidden">id</th>
										<th width="20%">系编号</th>
										<th width="20%">系名称</th>
										<th width="20%">办公地点</th>
										<th width="20%">系主任</th>
										<th width="20%">操作</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- Modal 新增学院-->
		<div class="modal fade" id="AddepModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">新增学院</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="form_add">
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">所属学院</label>
								<select class="form-control poiu removeSelect" id="sd_boss_add" name="sd_boss_add">
									<option value="0">请选择</option>
									<volist name="par_college" id="par_college">
										<option value="{$par_college.sch_id}">{$par_college.sch_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">系部编号</label>
								<div class="col-sm-7">
									<input type="text" id="add_dept_id" name="add_dept_id" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">系部名称</label>
								<div class="col-sm-7">
									<input type="text" id="add_dept_name" name="add_dept_name" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">办公地点</label>
								<div class="col-sm-7">
									<input type="text" id="add_dept_office" name="add_dept_office" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">负责人</label>
								<select class="form-control poiu removeSelect" id="tea_boss_add" name="tea_boss_add">
									<option value="0">请选择</option>
									<volist name="par_teacher" id="par_teacher">
										<option value="{$par_teacher.tea_id}">{$par_teacher.tea_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3  control-label " style="margin-top: 30px;">简介: </label>
								<div class="col-sm-7">
									<textarea id="add_dept_intro" name="add_dept_intro" class="form-control  cyf-inpput removeData" rows="" cols="" style="height: 150px;"></textarea>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="add_btn">保存</button>
					</div>
				</div>
			</div>
		</div>
		<!-- Modal 编辑学院-->
		<div class="modal fade" id="EditdepModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title">新增系部</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="form_edit">
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">所属学院</label>
								<select class="form-control poiu removeSelect" id="sd_boss_edit" name="sd_boss_edit">
									<option value="0">请选择</option>
									<volist name="par_college_edit" id="par_college_edit">
										<option value="{$par_college_edit.sch_id}">{$par_college_edit.sch_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学院编号</label>
								<div class="col-sm-7">
									<input type="text" id="edit_dept_id" name="edit_dept_id" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学院名称</label>
								<div class="col-sm-7">
									<input type="text" id="edit_dept_name" name="edit_dept_name" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">办公地点</label>
								<div class="col-sm-7">
									<input type="text" id="edit_dept_office" name="edit_dept_office" class="form-control removeData">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label cvbnm nationality">负责人</label>
								<select class="form-control poiu removeSelect" id="tea_boss_edit" name="tea_boss_edit">
									<option value="0">请选择</option>
									<volist name="par_teacher_edit" id="par_teacher_edit">
										<option value="{$par_teacher_edit.tea_id}">{$par_teacher_edit.tea_name}</option>
									</volist>
								</select>
							</div>
							<div class="form-group">
								<label class="col-sm-3  control-label " style="margin-top: 30px;">简介: </label>
								<div class="col-sm-7">
									<textarea name="edit_dept_intro" id="edit_dept_intro" class="form-control  cyf-inpput removeData" rows="" cols="" style="height: 150px;"></textarea>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="edit_btn">保存</button>
					</div>
				</div>
			</div>
		</div>
		<include file='Layout:ins_js' />
		<script type="text/javascript">
            //自检
            check_index();

			$(document).ready(function() {
				sTable = $(".table").DataTable({
					"fnServerParams": function(aoData) {
						aoData.push({
							'name': 'sch_id',
							'value': $('select#college_id option:selected').val(),
						});
					},
                    "bAutoWidth":false,
//                    "bLengthChange": false,
                    "sDom": "<'row'<'col-xs-6 inline'l><'col-xs-6 inline'f>r>" + "t" + "<'row'<'col-xs-6 inline'i><'col-xs-6 inline'p>>",
                    "sFilterInput": "form-control",
                    "sLengthSelect": "form-control",
                    "oLanguage": {
                        "sLengthMenu": "每页 _MENU_ ",
                        "sProcessing": "处理中...",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    },
					"sAjaxSource": "__URL__/department_manage_ShowDatatables", //调用php后台接口方法地址
					"aoColumns": [{
						'data': 'dept_id',
						"sClass": "hidden"
					}, {
						'data': 'dept_id',
					},{
						'data': 'dept_name',
					},{
						'data': 'dept_location',
					},{
						'data': 'tea_name',
					},{
						"data": null,
						orderable: false,
						render: function(data, type, row, meta) {
							return '<a type="button" class="btn btn-success" href="#" onclick=editFromID(this) >编辑</a>|<a type="button" class="btn btn-danger" href="#" onclick=delFromID(this) >删除</a>'
						}
					}, ]
				});
//				$("#langueType").val('0').trigger("change");
			});
			//查询按钮
			$("select#college_id").change(function() {
				//console.log( $('select#college_id option:selected').val());
				sTable.ajax.reload();
			});
			$("#addBtn").on('click', function() {
				$("#AddepModal").modal();
			});
			$("#add_btn").on('click', function() {
                var formData = $('#form_add').serializeArray();
                var postData = {};

                $(formData).each(function(i) {
                    postData[this.name] = this.value;
                });
				sil_loading();
				$.ajax({
					type: "post",
					url: "__URL__/add_department",
					async: true,
					data: postData,
					dataType: 'json',
					success: function(p) {
						if(p.state) {
							toastr.success(p.info);
							$("#AddepModal").modal('hide');
							sTable.ajax.reload();
						} else {
							toastr.warning(p.info);
						}
						sil_reloading();
					}
				});
			});
			function editFromID(obj) {
				var Obj = $(obj).parent().parent();
                var rowdata = sTable.row(Obj).data();
                $('#edit_dept_id').val(rowdata.dept_id);
				$('#edit_dept_name').val(rowdata.dept_name);
				$('#edit_dept_office').val(rowdata.dept_location);
				$('#edit_dept_intro').val(rowdata.dept_intro);
				$('#sd_boss_edit').val(rowdata.sch_id);
				$('#tea_boss_edit').val(rowdata.tea_id);
				$('.wrapper').removeClass('animated');
				$("#EditdepModal").modal();
			}
			$("#edit_btn").on('click', function() {
                var formData = $('#form_edit').serializeArray();
                var postData = {};
				$(formData).each(function(i) {
                    postData[this.name] = this.value;
                });
                sil_loading();
				$.ajax({
                    type: "post",
                    url: "__URL__/edit_department",
                    async: true,
                    data: postData,
                    dataType: 'json',
                    success: function(p) {
                        if(p.state) {
                            toastr.success(p.info);
                            $("#EditdepModal").modal('hide');
                            sTable.ajax.reload();
                        } else {
                            toastr.warning(p.info);
                        }
                        sil_reloading();
                    }
                });
			});

			function delFromID(obj) {
                var Obj = $(obj).parent().parent();
                var rowdata = sTable.row(Obj).data();
				swal({
					title: '提示',
					text: "确定要删除吗?",
					type: 'warning',
					showCancelButton: true,
					confirmButtonColor: '#3085d6',
					cancelButtonColor: '#d33',
					confirmButtonText: '确定',
					cancelButtonText: '取消'
				}).then(function(isConfirm) {
					if(isConfirm) {
						$.ajax({
							type: "post",
							url: "__URL__/delete_department",
							async: true,
							data: {
                                delete_dept_id: rowdata.dept_id,
							},
							dataType: 'json',
							success: function(p) {
								toastr.success(p.info);
								sTable.ajax.reload();
							}
						})
					}
				})
			}

		</script>
	</body>

</html>
